package com.bsoft.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

@Configuration
public class RedisConfiguration {
    @Bean
    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
        //创建redisTemplete 对象
        RedisTemplate<String, Object> template = new RedisTemplate<>();
        //   设置工厂
        template.setConnectionFactory(factory);
        //使用String  序列化方式 序列化key
        template.setKeySerializer(RedisSerializer.string());
        //使用JSON序列化的方式   序列化value
        template.setValueSerializer(RedisSerializer.json());
        return template;
    }
}
